<?php
class Magang_Model extends CI_Model{
	
	
	 function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
	function getData($limit, $offset, $judul=""){
		$sql="SELECT * from tbl_magang where asal_peserta like '%".$judul."%' order by id_magang desc limit $offset, $limit";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_detail_data($id){
		$sql="SELECT * from tbl_magang where id_magang='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function getAllData(){
		$sql="SELECT * from tbl_magang order by id_magang desc";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function count_all_num_rows($judul=""){
		$sql="SELECT * from tbl_magang where asal_peserta like '%".$judul."%' ";
		//echo $sql;
		$query=$this->db->query($sql);
		return $query->num_rows();
		
	}
	
	function insert_data($asal_peserta,$tgl_mulai,$tgl_selesai,$id_divisi){
		
		$data=array('asal_peserta'=>$asal_peserta,
					'tgl_mulai'=>$tgl_mulai,
					'tgl_selesai'=>$tgl_selesai,
					'id_divisi'=>$id_divisi
					);
		$insert=$this->db->insert('tbl_magang',$data);
		return $insert;
	}
	
	function update_data($id,$asal_peserta,$tgl_mulai,$tgl_selesai,$id_divisi){
		$data=array('asal_peserta'=>$asal_peserta,
					'tgl_mulai'=>$tgl_mulai,
					'tgl_selesai'=>$tgl_selesai,
					'id_divisi'=>$id_divisi
					);
		$this->db->where('id_magang',$id);
		$update=$this->db->update('tbl_magang',$data);
		return $update;
	}
	
	function delete_data($id){
		$data=array('id_magang'=>$id);
		$this->db->where($data);
		$delete=$this->db->delete('tbl_magang'); 
		return $delete;
	}
}
?>